package servlet.servlet_yaobo;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import pojo.HarvestAddress;
import pojo.MembershipManagement;
import service.impl.ImpShoppingMemberService;
import util.JsonDateValueProcessor;
import util.PageBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value ="/harvest" )
public class HarvestServelt extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ImpShoppingMemberService imp=new ImpShoppingMemberService();
        String id=req.getParameter("uid");
        PageBean<HarvestAddress> pa=new PageBean<>();
        pa=imp.membershipData(pa,Integer.parseInt(id));
        JSONObject obj=new JSONObject();
        obj.put("code",0);
        obj.put("mag","");
        JsonConfig config=new JsonConfig();
        config.registerJsonValueProcessor(java.util.Date.class,new JsonDateValueProcessor());
        obj.put("data",JSONArray.fromObject(pa.getList(),config));
        PrintWriter out=resp.getWriter();
        out.println(obj);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
